<?php
class Positions extends Model{
	
	function getActive(){
		$sql ="SELECT * FROM user_position p ";
        $sql .="WHERE p.enabled =1 ";
		$query=$this->db->query($sql);
		return $query->result_array();
	}
    
    function getCek(){
        $sql ="SELECT * FROM user_position p ";
		$sql.="WHERE p.pos_name = '".$this->input->post('name')."' LIMIT 1";
        $query=$this->db->query($sql);
		return $query->row_array();
    }
    
    function getSave(){
        $value = array  (
                            'pos_name'  =>  $this->input->post('name'),
                            'user_stamp'=>  $this->session->userdata('user_id'),
                            'enabled'   =>  1,
                            'date_stamp'=>  date('Y-m-d')
                        );               
        $this->db->insert('user_position',$value); 
    }
    
    function getUpdate(){
        $value = array  (
                            'pos_name'  =>  $this->input->post('name'),
                            'user_stamp'=>  $this->session->userdata('user_id'),
                            'date_stamp'=>  date('Y-m-d')
                        );
        $this->db->where('id',$this->input->post('id'));                 
        $this->db->update('user_position',$value); 
    }
    
    function getRemove(){
        $this->db->where('id',$this->input->post('id'));
        $this->db->delete('user_position');
    }
        
}